<?php
/**
 * Created by PhpStorm.
 * User: joe
 * Date: 2019-12-11
 * Time: 12:04
 */

namespace app\common\bean;

use app\common\bean\builder\StringBuilder;
use app\common\utils\StringUtil;

/**
 *  表实体Bean
 * Class TableBean
 * @package app\common\bean
 */
class TableBean extends BaseBean
{
    static $tableName = 'tableName'; //
    static $enumList = 'enumList'; //枚举量
    static $createProperty = 'createProperty'; //新增配置
    static $editProperty = 'editProperty'; //编辑配置
    static $listProperty = 'listProperty'; //查询列表配置
    static $delProperty = 'delProperty'; //删除配置

    /**
     * @return string
     */
    public function getCreateProperty()
    {
        return $this->getParameter(self::$createProperty);
    }

    /**
     * @param string $createProperty
     */
    public function setCreateProperty($createProperty)
    {
        $this->setParameter(self::$createProperty, $createProperty);
    }

    /**
     * @return string
     */
    public function getEditProperty()
    {
        return $this->getParameter(self::$editProperty);
    }

    /**
     * @param string $editProperty
     */
    public function setEditProperty($editProperty)
    {
        $this->setParameter(self::$editProperty, $editProperty);
    }

    /**
     * @return string
     */
    public function getListProperty()
    {
        return $this->getParameter(self::$listProperty);
    }

    /**
     * @param string $listProperty
     */
    public function setListProperty($listProperty)
    {
        $this->setParameter(self::$listProperty, $listProperty);
    }

    /**
     * @return string
     */
    public function getDelProperty()
    {
        return $this->getParameter(self::$delProperty);
    }

    /**
     * @param string $delProperty
     */
    public function setDelProperty($delProperty)
    {
        $this->setParameter(self::$delProperty, $delProperty);
    }

    /**
     * @return mixed
     */
    public function getEnumList()
    {
        return $this->getParameter(self::$enumList);
    }

    /**
     * @param $tableName
     */
    public function setEnumList($tableName)
    {
        $this->setParameter(self::$enumList, $tableName);
    }

    /**
     * @return string
     */
    public function getTableName()
    {
        return $this->getParameter(self::$tableName);
    }

    /**
     * @param string $tableName
     */
    public function setTableName($tableName)
    {
        $this->setParameter(self::$tableName, $tableName);
    }


    /**
     * 获取curd得验证场景
     * @param $beanName
     * @return string
     */
    public function getCurdValidateScene($beanName)
    {
        #新增
        $stringBuilder = (new StringBuilder())->concatStringEnter("self::\$add => [");
        if ($this->getCreateProperty()) {
            foreach ($this->getCreateProperty() as $item) {
                $columnMap = new ListMap();
                $columnMap->setData($item);
                !StringUtil::getInstance()->is_true($columnMap->getParameter("notNull"))?:$stringBuilder->concatStringEnter("{$beanName}::\$".StringUtil::getInstance()->convertUnderline($columnMap->getParameter('COLUMN_NAME')).",",4);
            }
        }
        $stringBuilder->concatStringEnter("],",3);

        #编辑
        $stringBuilder->concatStringEnter("self::\$edit => [",3);
        if ($this->getEditProperty()) {
            foreach ($this->getEditProperty() as $item) {
                $columnMap = new ListMap();
                $columnMap->setData($item);
                !StringUtil::getInstance()->is_true($columnMap->getParameter("notNull"))?:$stringBuilder->concatStringEnter("{$beanName}::\$".StringUtil::getInstance()->convertUnderline($columnMap->getParameter('COLUMN_NAME')).",",4);
            }
        }
        $stringBuilder->concatStringEnter("],",3);

        #删除
        $stringBuilder->concatStringEnter("self::\$pkId => [],",3);
        if ($this->getDelProperty()) {

        }
        return $stringBuilder->getContent();
    }

    /** 生成制表符
     * @param int $count
     * @return string
     */
    protected function getTab($count = 1)
    {
        return str_repeat("\t", $count);
    }

    /** 生成回车符
     * @param int $count
     * @return string
     */
    protected function getEnter($count = 1)
    {
        return str_repeat("\n", $count);
    }
}